package cn.edu.scau.cmi.chenmiaopeng.controller.factory;

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.control.TextArea;

import cn.edu.scau.cmi.chenmiaopeng.factory.abstractFactory.MeatProducer.*;
import cn.edu.scau.cmi.chenmiaopeng.factory.abstractFactory.MeatProduct.*;

public class AbstractFactoryController {
	@FXML
    private Button confirm;

	@FXML
    private Button confirm_buy;
	
    @FXML
    private TextArea textarea;

    @FXML
    private ComboBox<String> comboBox;
    
    @FXML
    private ComboBox<String> comboBox1;
    
    @FXML
    private ComboBox<String> comboBox2;
    
    private MeatProducer meatProducer;
    private MeatProduction meatProduction;
    private boolean hasSeenInfo = false;
    public void clickButton(ActionEvent e) {
    	String brand_option = comboBox2.getValue();
    	String meat_option =  comboBox.getValue();
    	meatProducer = null;
    	if(meat_option.equals("please choose meat:")||brand_option.equals("please choose brand:")) {
			textarea.appendText("please choose the meat and the brand you want!\n");
			hasSeenInfo = false;
		}
    	else {
    		if(brand_option.equals("Aonong")){
				meatProducer = new Aonong();
			}
			else if(brand_option.equals("Tianbang")) {
				meatProducer = new Tianbang();
			}
			else {
				meatProducer = new Wens();
			}
    		
    		meatProduction = null;
			if(meat_option.equals("Pork")) {
				meatProduction = meatProducer.getPorkProduction();
			}
			else if(meat_option.equals("Chicken")) {
				meatProduction = meatProducer.getChickenProduction();
			}
			else {
				meatProduction = meatProducer.getBeefProduction();
			}
    		if((Button)e.getSource()==confirm) {
    			textarea.clear();
    			textarea.appendText(meatProduction.getProductionInfo()+"\n");
    			hasSeenInfo = true;
    		}
    		else if((Button)e.getSource()==confirm_buy) {
    			String select = comboBox1.getSelectionModel().getSelectedItem();
    			if(select==null) {
    				return ;
    			}
    			if(select.equals("yes")) {
    				if(!hasSeenInfo) {
    					textarea.clear();
    					textarea.appendText("You haven't see the production info, are you sure to buy?\n");
    					hasSeenInfo = true;
    				}
    				else {
    					textarea.appendText(meatProduction.produce()+"\n");
    					comboBox.getSelectionModel().selectFirst();
            			comboBox2.getSelectionModel().selectFirst();
            			comboBox1.setValue("want to buy?");
            			hasSeenInfo = false;
    				}
        		}
    			else {
    				textarea.appendText("thanks for coming!\n");
    				comboBox.getSelectionModel().selectFirst();
        			comboBox2.getSelectionModel().selectFirst();
        			comboBox1.setValue("want to buy?");
        			hasSeenInfo = false;
    			}
    		}
    	}
    }
}
